package com.asm.controller.api;

import com.asm.controller.BaseController;
import com.asm.dto.PageResult;
import com.asm.dto.Result;
import com.asm.service.CommunityTagService;
import com.asm.vo.sys.CommunityTagVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author tanzujie
 */
@ApiModel("用于处理预定信息的Controller层接口")
@Slf4j
@RestController
public class CommunityTagController extends BaseController {
    @Resource
    private CommunityTagService communitytagService;

    /**
     * 分页查询所有小区标签
     *
     * @param pageNumber 当前页码
     * @param pageSize   页面大小
     * @return 小区标签
     */
    @ApiOperation("分页查询所有小区标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    @GetMapping("/communitytags")
    public ResponseEntity<PageResult<CommunityTagVo>> getAllCommunityTags(@RequestParam(value = "pageNumber", defaultValue = "0") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "15") Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findAllCommunityTags(pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 根据Id获取小区标签
     *
     * @param id 标签编号
     * @return 小区标签
     */
    @ApiOperation("根据Id获取小区标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "小区标签编号")
    })
    @GetMapping("/communitytag/{id}")
    public ResponseEntity<Result<CommunityTagVo>> getCommunityTagById(@PathVariable("id") Long id) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findCommunityTagById(id)), HttpStatus.OK);
    }

    /**
     * 根据小区标签类型分页查询小区标签
     *
     * @param type 标签类型
     * @param pageNumber 页码
     * @param pageSize   页大小
     * @return 小区标签
     */
    @ApiOperation("根据小区标签类型分页查询小区标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "标签类型"),
            @ApiImplicitParam(name = "pageNumber", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    @GetMapping("/communitytags/type/{type}")
    public ResponseEntity<PageResult<CommunityTagVo>> getCommunityTagsByType(@PathVariable("type") String type, @RequestParam(value = "pageNumber", defaultValue = "0") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "15") Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findCommunityTagBytagType(type, pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 根据小区标签大小分页查询小区标签
     *
     * @param communityid 小区编号
     * @param pageNumber  当前页码
     * @param pageSize    页面大小
     * @return 小区标签
     */
    @ApiOperation("根据小区标签大小分页查询小区标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "communityid", value = "小区编号"),
            @ApiImplicitParam(name = "pageNumber", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    @GetMapping("/communitytags/communityid/{communityid}")
    public ResponseEntity<PageResult<CommunityTagVo>> getCommunityTagsBySize(@PathVariable("communityid") Long communityid, @RequestParam(value = "pageNumber", defaultValue = "0") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "15") Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", communitytagService.findCommunityTagByCommunityId(communityid, pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     * 增加小区标签
     *
     * @param communitytagVo 小区标签对象
     * @return 操作状态
     */
    @ApiOperation("增加小区标签")
    @PostMapping("/communitytag/add")
    public ResponseEntity<Result> addCommunityTag(@RequestBody @ApiParam(name = "communityTagVo", value = "小区标签") CommunityTagVo communitytagVo) {
        communitytagService.addCommunityTag(communitytagVo);
        return new ResponseEntity(new Result().ok("add success"), HttpStatus.OK);
    }

    /**
     * 更新小区标签
     *
     * @param communitytagVo 小区标签
     * @return 操作状态
     */
    @ApiOperation("更新小区标签")
    @PutMapping("/communitytag/update")
    public ResponseEntity<Result> updateCommunityTag(@RequestBody @ApiParam(name = "communityTagVo", value = "小区标签") CommunityTagVo communitytagVo) {
        communitytagService.updateCommunityTag(communitytagVo);
        return new ResponseEntity(new Result().ok("update success"), HttpStatus.OK);
    }

    /**
     * 根据Id删除小区标签
     *
     * @param id 小区标签编号
     * @return 操作状态
     */
    @ApiOperation("根据Id删除小区标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "小区标签编号")
    })
    @DeleteMapping("/communitytag/delete/{id}")
    public ResponseEntity<Result> deleteCommunityTag(@PathVariable("id") Long id) {
        communitytagService.deleteCommunityTag(id);
        return new ResponseEntity(new Result().ok("delete success"), HttpStatus.OK);
    }
}
